# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

include('js-config.mozbuild')
include('js-cxxflags.mozbuild')
include('js-testing.mozbuild')

CONFIGURE_SUBST_FILES += [
    'js-config',
    'js.pc',
]

CONFIGURE_DEFINE_FILES += [
    'js-confdefs.h',
]

if not CONFIG['JS_STANDALONE']:
    LIBRARY_DEFINES['MOZ_HAS_MOZGLUE'] = True

    CONFIGURE_SUBST_FILES += [
        '../../config/autoconf-js.mk',
        '../../config/emptyvars-js.mk',
    ]

CONFIGURE_DEFINE_FILES += [
    'js-config.h',
]

if CONFIG['HAVE_DTRACE']:
    GENERATED_FILES += ['javascript-trace.h']
    EXPORTS += ['!javascript-trace.h']

# Changes to internal header files, used externally, massively slow down
# browser builds.  Don't add new files here unless you know what you're
# doing!
EXPORTS += [
    '!js-config.h',
    'js.msg',
    'jsalloc.h',
    'jsapi.h',
    'jsbytecode.h',
    'jsclist.h',
    'jscpucfg.h',
    'jsfriendapi.h',
    'jsprf.h',
    'jsprototypes.h',
    'jspubtd.h',
    'jstypes.h',
    'jsversion.h',
    'jswrapper.h',
]

# If you add a header here, add it to js/src/jsapi-tests/testIntTypesABI.cpp so
# that we ensure we don't over-expose our internal integer typedefs.  Note that
# LegacyIntTypes.h below is deliberately exempted from this requirement.
EXPORTS.js += [
    '../public/CallArgs.h',
    '../public/CallNonGenericMethod.h',
    '../public/CharacterEncoding.h',
    '../public/Class.h',
    '../public/Conversions.h',
    '../public/Date.h',
    '../public/Debug.h',
    '../public/GCAnnotations.h',
    '../public/GCAPI.h',
    '../public/GCHashTable.h',
    '../public/GCPolicyAPI.h',
    '../public/GCVariant.h',
    '../public/GCVector.h',
    '../public/HashTable.h',
    '../public/HeapAPI.h',
    '../public/Id.h',
    '../public/Initialization.h',
    '../public/LegacyIntTypes.h',
    '../public/MemoryMetrics.h',
    '../public/Principals.h',
    '../public/ProfilingFrameIterator.h',
    '../public/ProfilingStack.h',
    '../public/Proxy.h',
    '../public/Realm.h',
    '../public/RequiredDefines.h',
    '../public/RootingAPI.h',
    '../public/SliceBudget.h',
    '../public/StructuredClone.h',
    '../public/SweepingAPI.h',
    '../public/TraceKind.h',
    '../public/TracingAPI.h',
    '../public/TrackedOptimizationInfo.h',
    '../public/TypeDecls.h',
    '../public/UbiNode.h',
    '../public/UbiNodeBreadthFirst.h',
    '../public/UbiNodeCensus.h',
    '../public/UbiNodeDominatorTree.h',
    '../public/UbiNodePostOrder.h',
    '../public/UbiNodeShortestPaths.h',
    '../public/UniquePtr.h',
    '../public/Utility.h',
    '../public/Value.h',
    '../public/Vector.h',
    '../public/WeakMapPtr.h',
]

DIRS += [
    'builtin',
    'devtools',
    'ds',
    'frontend',
    'gc',
    'irregexp',
    'jit',
    'perf',
    'proxy',
    'threading',
    'wasm',
]

if CONFIG['JS_HAS_CTYPES']:
    DIRS += ['ctypes']

if CONFIG['JS_BUNDLED_EDITLINE']:
    DIRS += ['editline']

if CONFIG['JS_NEW_REGEXP']:
    DIRS += ['new-regexp']

if not CONFIG['JS_DISABLE_SHELL']:
    DIRS += ['shell']

if CONFIG['MOZ_VTUNE']:
    DIRS += ['vtune']

UNIFIED_SOURCES += [
    'jsalloc.cpp',
    'jsapi.cpp',
    'jsbool.cpp',
    'jscntxt.cpp',
    'jscompartment.cpp',
    'jsdate.cpp',
    'jsexn.cpp',
    'jsfriendapi.cpp',
    'jsfun.cpp',
    'jsgc.cpp',
    'jsiter.cpp',
    'jsnativestack.cpp',
    'jsnum.cpp',
    'jsobj.cpp',
    'json.cpp',
    'jsopcode.cpp',
    'jsprf.cpp',
    'jspropertytree.cpp',
    'jsscript.cpp',
    'jsstr.cpp',
    'jsweakmap.cpp',
]

# Can't be built unified
SOURCES += [
    'jsarray.cpp',
    'jsatom.cpp',
    'jsdtoa.cpp',
    'jsmath.cpp',
    'jsutil.cpp',
]

# Suppress warnings in third-party code.
# We are keeping this in the main moz.build because it is file specific
if CONFIG['CLANG_CXX'] or CONFIG['GNU_CXX']:
    SOURCES['jsdtoa.cpp'].flags += ['-Wno-implicit-fallthrough']

UNIFIED_SOURCES += [
    'vm/ArgumentsObject.cpp',
    'vm/ArrayBufferObject.cpp',
    'vm/AsyncFunction.cpp',
    'vm/AsyncIteration.cpp',
    'vm/Caches.cpp',
    'vm/CallNonGenericMethod.cpp',
    'vm/CharacterEncoding.cpp',
    'vm/CodeCoverage.cpp',
    'vm/Compression.cpp',
    'vm/DateTime.cpp',
    'vm/Debugger.cpp',
    'vm/DebuggerMemory.cpp',
    'vm/EnvironmentObject.cpp',
    'vm/ErrorObject.cpp',
    'vm/ForOfIterator.cpp',
    'vm/GeneratorObject.cpp',
    'vm/GlobalObject.cpp',
    'vm/HelperThreads.cpp',
    'vm/Id.cpp',
    'vm/Interpreter.cpp',
    'vm/JSONParser.cpp',
    'vm/MemoryMetrics.cpp',
    'vm/NativeObject.cpp',
    'vm/ObjectGroup.cpp',
    'vm/PIC.cpp',
    'vm/Printer.cpp',
    'vm/Probes.cpp',
    'vm/ProxyObject.cpp',
    'vm/Realm.cpp',
    'vm/ReceiverGuard.cpp',
    'vm/RegExpObject.cpp',
    'vm/RegExpStatics.cpp',
    'vm/Runtime.cpp',
    'vm/SavedStacks.cpp',
    'vm/Scope.cpp',
    'vm/SelfHosting.cpp',
    'vm/Shape.cpp',
    'vm/SharedArrayObject.cpp',
    'vm/SharedImmutableStringsCache.cpp',
    'vm/SPSProfiler.cpp',
    'vm/Stack.cpp',
    'vm/Stopwatch.cpp',
    'vm/String.cpp',
    'vm/StringBuffer.cpp',
    'vm/StructuredClone.cpp',
    'vm/Symbol.cpp',
    'vm/TaggedProto.cpp',
    'vm/Time.cpp',
    'vm/TypedArrayObject.cpp',
    'vm/TypeInference.cpp',
    'vm/UbiNode.cpp',
    'vm/UbiNodeCensus.cpp',
    'vm/UbiNodeShortestPaths.cpp',
    'vm/UnboxedObject.cpp',
    'vm/Unicode.cpp',
    'vm/Value.cpp',
    'vm/WeakMapPtr.cpp',
    'vm/Xdr.cpp',
]

# Can't be built unified
SOURCES += [
    'vm/Initialization.cpp',
]

if CONFIG['JS_POSIX_NSPR']:
    UNIFIED_SOURCES += [
        'vm/PosixNSPR.cpp',
    ]

if CONFIG['ENABLE_TRACE_LOGGING']:
    # Can't be built unified
    SOURCES += [
        'vm/TraceLogging.cpp',
        'vm/TraceLoggingGraph.cpp',
        'vm/TraceLoggingTypes.cpp',
    ]

# JavaScript must be built shared, even for static builds, as it is used by
# other modules which are always built shared. Failure to do so results in
# the js code getting copied into xpinstall and jsd as well as mozilla-bin,
# and then the static data cells used for locking no longer work.
#
# In fact, we now build both a static and a shared library, as the
# JS shell would like to link to the static library.

if CONFIG['JS_SHARED_LIBRARY']:
    GeckoSharedLibrary('js', linkage=None)
    SHARED_LIBRARY_NAME = CONFIG['JS_LIBRARY_NAME']
    SDK_LIBRARY = True
else:
    Library('js')

FORCE_STATIC_LIB = True
STATIC_LIBRARY_NAME = 'js_static'

if not CONFIG['MOZ_ICU_DATA_ARCHIVE']:
    USE_LIBS += [
        'icu',
    ]
else:
    # Linking 'icu' will pull in the stubdata library,
    # which the shell doesn't want, so link the other bits.
    USE_LIBS += [
        'icui18n',
        'icuuc',
    ]

USE_LIBS += [
    'nspr',
    'zlib',
]

if CONFIG['OS_ARCH'] not in ('WINNT'):
    OS_LIBS += ['m']

if CONFIG['OS_ARCH'] == 'FreeBSD':
    OS_LIBS += ['-pthread']

if CONFIG['OS_ARCH'] == 'Linux':
    OS_LIBS += ['dl']

if CONFIG['OS_ARCH'] == 'SunOS':
    OS_LIBS += [
        'posix4',
        'dl',
        'nsl',
        'socket',
    ]

OS_LIBS += CONFIG['REALTIME_LIBS']

NO_EXPAND_LIBS = True

DIST_INSTALL = True


